﻿@using System
@using YYBlog.Core.Extensions
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<YYBlog.Core.Commands.Posts.NewPostCommand>
@{
    ViewBag.Title = "Add new Post";
    Layout = "_AdminLayout.cshtml";
}
@section PostStyle{
    <link href="/Content/css/bootstrap-markdown.min.css" rel="stylesheet" />
}
<div class="title">添加文章</div>
<div class="card">
    <div class="card-body">
        <form method="post" role="form" action="/yy-admin/posts/new">
            <div class="form-group">
                <input id="post-title" type="text" class="form-control" name="Title" placeholder="标题" value="@Model.Title" required />
            </div>
            <div class="form-group">
                <input id="post-slug" type="text" class="form-control" name="TitleSlug" placeholder="固定链接Key" value="@Model.TitleSlug" required />
            </div>
            <div class="form-group">
                <textarea id="post-content" data-provide="markdown" rows="20" name="MarkDown" placeholder="内容" required>@Model.MarkDown</textarea>
            </div>
            <div class="form-group">
                <input name="Tags" id="tags" class="form-control" value="@Model.Tags" />
            </div>
            <input id="pubdate" name="PubDate" type="hidden" value="@(Model.PubDate != DateTime.MinValue ? Model.PubDate : DateTime.Now)" />
            <div class="form-group">
                <div class="form-check">
                    <label class="form-check-label">
                        <input class="form-check-input" name="Published" value="true" type="checkbox">发布
                    </label>
                </div>
            </div>
            <div class="form-group">
                <input type="submit" value="保存" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>
@section PostScripts{
    <script src="/Content/js/bootstrap-markdown.js"></script>
    <script src="/Content/js/bootstrap-markdown.zh.js"></script>
    <script src="/Content/js/jquery.tagsinput.js"></script>
    <script src="/Content/js/markdown.js"></script>
    <script>
        $('#tags').tagsInput({ 'width': '100%', 'defaultText': '添加标签' });
        $('#post-title').on('change', function () {
            var _title = $(this).val();
            if ($("#post-slug").val() == "") {
                $.post("/yy-admin/slug", { title: _title }, function (data) {
                    $("#post-slug").val(data);
                });
            }
        });
    </script>
}